//
//  MyBidListViewModel.swift
//  cxd4iphone
//
//  Created by hexy on 12/15/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit
import ReactiveCocoa

class MyInvestListViewModel: BaseTableListViewModel {

//    override init() {
//        
//        super.init()
//        
//        let vm1 = MyBidCellViewModel()
//        
//        self.sections = [[vm1, vm1, vm1, vm1, vm1, vm1, vm1, vm1]]
//    }
    
    lazy var queryModel = QueryModel(dict: ["":""])
    
    static var page: Int = 1
    func loadUserInvestRecord(pullDown: Bool) -> RACSignal {
        
        return RACSignal.createSignal({ (subscriber) -> RACDisposable! in
            
            self.queryModel.currentPage = pullDown ? 1 : MyInvestListViewModel.page++
            
            
            APIManager.loadUserInvestRecord(self.queryModel).subscribeNext({ (result) -> Void in
                
                xx_JsonPrint(dict: result)
                let array = result as! [[String: AnyObject]]
                
                var arrM = [MyInvestCellViewModel]()
                for dict in array {
                    
                    arrM.append(MyInvestCellViewModel(bidModel: BidModel(dict: dict)))
                }
                
                self.sections = [arrM]
                subscriber.sendCompleted()
                
                }, error: { (error) -> Void in
                    
                    subscriber.sendError(error)
            })

            return RACDisposable(block: {})
        })
    }
    
    lazy var pickerViewModel: PickerViewModel = {
        
        let pvm = PickerViewModel()
        
        pvm.components = [PickerQueryViewModel.shared.loanInvestStatus]
        return pvm
    }()

}
